import { defineStore } from "pinia";

export const useUserStore = defineStore("user", {
  state: () => ({
    isLogin: !!localStorage.getItem("token"),
  }),
  actions: {
    updateLoginStatus() {
      const token = localStorage.getItem("token");
      const userId = localStorage.getItem("userId");
      const newStatus = !!(token && userId);

      console.log("更新登录状态 - localStorage:", {
        token: token ? "存在" : "不存在",
        userId: userId ? "存在" : "不存在",
        tokenValue: token,
        userIdValue: userId,
        newStatus,
      });

      this.isLogin = newStatus;
    },
  },
});
